function addListener(element, e, fn) {
      if (element.addEventListener) {
            element.addEventListener(e, fn, false);
      } else {
            element.attachEvent("on" + e, fn);
      }
}

$(function(){

      /**
       * 导航分类栏方法
       */
      $('.mn_sort > .mn_mc > .item').hover(function(){
            $(this).addClass('item_hover');
            $(this).children('.i_bd').show();
      },function(){
            $(this).removeClass('item_hover');
            $(this).children('.i_bd').hide();
      });
      /**
       * 联系方式模块微信二维码
       */
      $('.weixin').hover(function(){
            $(this).find('.erweima').show();
      },function(){
            $(this).find('.erweima').hide();
      });

      /**
       *页面用JS，含搜索，侧边栏滚动
       */
      $("#head_searchSubmit").mouseover(function(){
            $(this).parent().addClass('tp_txt_focus');
      }).mouseleave(function(){
            $(this).parent().removeClass('tp_txt_focus');
      });
      $(".topR_search").inputTips();
      $("#head_searchKeywords").prev("span.iptTips").css({"left":"1px", "top":"0px"});

      $("#searchType").click(function(){
            var obj = $(this);
            var pobj = $("#searchTypeList");
            var course = $("#courseType").clone();
            var school = $("#schoolType").clone();
            obj.showMenu('#searchTypeList');
            obj.mouseout(function(){
                  obj.hideMenu('#searchTypeList');
            });

            pobj.find("a").click(function(){
                  var cobj = $(this);
                  obj.attr('stype', cobj.attr('stype')).html(cobj.text()+'<i class="icoR icoR_5"></i>');
                  if(cobj.attr('stype') == 'school'){
                        $("#courseType").remove();
                        $("#schoolType").after(course);
                  } else {
                        $("#schoolType").remove();
                        $("#courseType").after(school);
                  }
                  pobj.hide();
            });
      });

      $("#head_searchKeywords").keydown(function(event){
            if(event.keyCode == 13){
                  $("#head_searchSubmit").trigger('click');
            }
      });

      /**
       * 发起搜索逻辑
       */
      $("#head_searchSubmit").click(function(){
            var keywords = $.trim($("#head_searchKeywords").val()),
                  searchType = $("#searchType").attr('stype');
            if(searchType == "course"){
                  if(keywords == ''){
                        searchUrl = "/course";
                  }else{
                        searchUrl = "/course?kws="+encodeURIComponent(keywords);
                  }
            }else{
                  searchUrl = "/course";
            }
            document.location.href = searchUrl;
            return false;
      });
      $(window).scroll(function(){
            if ($(window).scrollTop()>100){
                  $("li.r_gotop").fadeIn(750);
            }else{
                  $("li.r_gotop").fadeOut(750);
            }
      });
      addListener(document, "mouseover",function(evt) {
            var evt = window.event ? window.event: evt,
                  target = evt.srcElement || evt.target;
            if(target.id == "btnWeixin") {
                  $("#btnWeixin").animate({left: '-66px'}, "fast");
                  return;
            }else if(target.id == "btnFeedback"){
                  $("#btnFeedback").animate({left: '-66px'}, "fast");
                  return;
            }else if(target.id == "btnGotop"){
                  $("#btnGotop").animate({left: '-66px'}, "fast");
                  return;
            }else if(target.id == "customerService"){
                  $("#customerService").animate({left: '-66px'}, "fast");
                  return;
            }
      });
      addListener(document, "mouseout",function(evt) {
            var evt = window.event ? window.event: evt,
                  target = evt.srcElement || evt.target;
            if(target.id == "btnWeixin") {
                  $("#btnWeixin").stop(true).animate({left: '0px'}, "fast");
                  return;
            }else if(target.id == "btnFeedback"){
                  $("#btnFeedback").stop(true).animate({left: '0px'}, "fast");
                  return;
            }else if(target.id == "btnGotop"){
                  $("#btnGotop").stop(true).animate({left: '0px'}, "fast");
                  return;
            }else if(target.id == "customerService"){
                  $("#customerService").stop(true).animate({left: '0px'}, "fast");
                  return;
            }
      });

      $("#weixinClose").click(function(){
            $("#weixinCodeImg").hide();
            $("#btnWeixin").css("display","block");
      });
      $("#btnWeixin").click(function(){
            $("#btnWeixin").css("display","none");
            $("#weixinCodeImg").show();
      })
});